<?php
/*
文章管理模块
*/
include_once('include/top.php');

$action=fs_get_value("do");
switch($action)
{
	case	"addnew"	:	addnew()	;	break;
	case	"delete"	:	delete()	;	break;
	default				:	main()		;	break;
}




//***********************************************************
//**********************管理文章*****************************
//***********************************************************
function main()
{
	global $db;

	//取总条数
	$sql = "select * from 7sx_major";	
	$result = $db->query($sql);
	$resultcount = $db->num_rows($result);

	//pagebar
	@$page=fs_get_value('p');							//接收页码
	if ($page==null){$page=1;}
	$pagesize=10;								//每页显示数
	$pagecount=ceil($resultcount/$pagesize);	//计算总页
	if ($page>$pagecount){$page=$pagecount;}
	if ($page<1){$page=1;}
	$startnum=($page-1)*($pagesize)
	//pagebarend

?>
<script src="./js/Main.js"></script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
    <th class="CTitle">专业管理</th>
  </tr>
  <tr>
    <td class="CPanel">
    <div class="SubMenu"><a href="?do=manage">专业管理</a> | <a href="?do=add">添加专业</a></div>
	<?php if(fs_get_value("do")=="manage") { ?>
		<form action="?do=manage" method="post" name="fooeeform" style="margin:0px">
		<table border="0" cellpadding="0" cellspacing="0"  class="TablePanel" width="100%">
			<tr align="center" class="TDHead">
			<td nowrap width="8%"><input type=button style="font-size:9pt;width:50px;" value="全选" onclick="click_allid(fooeeform,1)"></td>
			<td nowrap width="8%"><input type=button style="font-size:9pt;width:50px;" value="全取" onclick="click_allid(fooeeform,0)"></td>
			<td nowrap width="8%"><input type=submit name='delete_major' style="font-size:9pt;width:50px;" value="删除"></td>

			<td nowrap></td>
			<td nowrap></td>
			<td nowrap></td>
			<td width="30%" nowrap></td>
			<td nowrap></td>
			</tr>
		</table>

<div id="click_idall">
    <div align="left" style="padding:5px;">
      <table border="0" cellpadding="0" cellspacing="0" class="TablePanel" align="center" width="100%">
        <tr align="center">
		  <td class="TDHead">√</td>
          <td class="TDHead" nowrap>专业id</td>
          <td class="TDHead" nowrap>专业名称</td>   
		  <td class="TDHead" nowrap>操作</td>
        </tr>
<?php


	$result=$db->query("select * from 7sx_major order by major_id limit ".$startnum.",$pagesize ");
	while($row = $db->fetch_array($result))
	{
?>
		<tr id=""  onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='FFFFFF'" title=单击选中 align="center">
		<td><input name='id[]' type='checkbox' id="" value=<?php echo($row['major_id']);?>></td>
			<td><?php echo($row['major_id']);?></td>
			<td><?php echo($row['name']);?></a></td>
			<td><a href="?do=edit&id=<?php echo($row['major_id']);?>">编辑</a></td>
		</tr>
		<tr>
			<td height=1 colspan=9 bgcolor="#E8F1FF" onMouseOver="bgColor='#FF8899'" onMouseOut="bgColor='E7E7E7'"></td>
		</tr>
<?php
	}	
?>
	</table>
	</form>
	<?php
				if(fs_get_value("delete_major")!==''){
	                    $id = fs_get_value("id");
	                   if(!is_array($id)){
                        $sql="delete from 7sx_major where major_id=".fs_get_value("id");
					   }
					   else{
					     
						 $str_id = implode(",",$id);
						 $sql="delete from 7sx_major where major_id in(".$str_id.")";
					   }
						$result = $db->query($sql);
						$result? fs_showmsg("删除成功!"):fs_showmsg("删除过程中出现错误,请检查!");
                    }
				
			?>
	</div>
	<center><?php
/*分页示例:

pager(传入URL , 数据总数 , 开始条数 , 每页数目)
*/
echo(pager('?do=manage&p={page}',$resultcount,$startnum,$pagesize));		
?></center>
	</td>
	</tr>
	</table>

<?php
}	
elseif(fs_get_value("do")=="add"){
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
<form  action="" method="post" name="add_major">
<tr align="center"><td height=25>专业名称:</td><td><input type="text" name="major_name" /></td><td><input type="submit" value="添加" name="add_major"></td></tr>
</form>
<?php
   if(fs_get_value("add_major")!==''){
	if(fs_get_value("major_name")=="")fs_showmsg("专业名称不能为空");
           $sql="insert into 7sx_major (major_id,name) values ('','".fs_get_value("major_name")."')";
		   $result =$db->query($sql);
		   $result?fs_showmsg("专业添加成功!"):fs_showmsg("添加过程中出现错误,请检查!");
   }
?>
</table>
<?php
}	
elseif(fs_get_value("do")=="edit"){
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
<?php 
$sql ="select * from 7sx_major where major_id=".fs_get_value("id");
$result=$db->query($sql);
?>
<form  action="" method="post" name="add_major">
<tr align="center"><td>专业名称:</td><td>
<?php 
	while($row=$db->fetch_array($result)){
          echo '<input type="text" name="major_name" value="'.$row['name'].'" /></td><td><input type="submit" value="修改" name="edit_major">';
}  ?>
<?php
 if(fs_get_value("edit_major")!=''){
     $sql ="update 7sx_major set name='".fs_get_value("major_name")."' where major_id=".fs_get_value("id");
	 $result=$db->query($sql);
	 $result?fs_showmsg("修改成功!","admin_major.php?do=manage"):fs_showmsg("修改过程中出现错误,请检查!");
   }

	?>
		  </td></tr>
</form>
<?php
}
}
?>